#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 10005;
int n,m;
int fa[maxn];

int findf(int x)
{
    return fa[x] == x ? x : fa[x] = findf(fa[x]);
}

bool join(const int &u, const int &v)
{
    int f1 = findf(u), f2 = findf(v);
    if (f1 == f2) return false;
    else { fa[f2] = f1; return true; }
}


int main(){
	cin>>n>>m;
	int z,x,y;
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++){
		cin>>z>>x>>y;
		if(z==1){
			join(x,y);
		}else{
			if(findf(x)==findf(y))cout<<"Y"<<endl;
			else cout<<"N"<<endl;
		}
	}
	return 0;
}
